package com.chaoxuan.uebt.utils;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chaoxuan.uebt.R;

public class CommomDialog2 extends Dialog implements View.OnClickListener{
        private TextView contentTxt;
        private TextView titleTxt;
        private TextView submitTxt;


        private Context mContext;
        private String content;
        private String positiveName;
        private String negativeName;
        private String title;
        private OnCloseListener listener;

    public CommomDialog2(Context context) {
            super(context);
            this.mContext = context;
    }

    public CommomDialog2(Context context, int themeResId, String content) {
            super(context, themeResId);
            this.mContext = context;
            this.content = content;
    }



    public CommomDialog2(Context context,int themeResId,String content,OnCloseListener listener) {
            super(context,themeResId);
            this.mContext = context;
            this.content = content;
            this.listener=listener;
        }

        public CommomDialog2 setTitle(String title){
            this.title = title;
            return this;
        }

        public CommomDialog2 setPositiveButton(String name){
            this.positiveName = name;
            return this;
        }

        public CommomDialog2 setNegativeButton(String name){
            this.negativeName = name;
            return this;
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.layout_dialog2);
            setCanceledOnTouchOutside(false);
            initView();
        }

        private void initView(){
            contentTxt = (TextView)findViewById(R.id.content);
            titleTxt = (TextView)findViewById(R.id.title);
            submitTxt = (TextView)findViewById(R.id.submit);
            submitTxt.setOnClickListener(this);

            contentTxt.setText(content);
            if(!TextUtils.isEmpty(positiveName)){
                submitTxt.setText(positiveName);
            }

            if(!TextUtils.isEmpty(title)){
                titleTxt.setText(title);
            }

        }

        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.submit:
                    if(listener != null){
                        listener.onClick(this, false);
                    }
                    this.dismiss();
                    break;
            }
        }
    public interface OnCloseListener{
        void onClick(Dialog dialog, boolean confirm);
    }

}
